import os
import platform

mainclass = "tianxiao.web.test.App"

# 判断操作系统,
sysstr = platform.system()

print("当前操作系统:　" + sysstr)
isWindows = sysstr == "Windows"

if isWindows:
    print("构建依赖")
    os.system("mvn dependency:copy-dependencies -DoutputDirectory=target/classes/lib")


def read(stream):
    lines = stream.readlines()
    # 按行遍历
    for line in lines:
        line = line.strip('\r\n' if isWindows else '\n')
        print(line)


print("")
print("")

if isWindows:
    if os.system("python stop.py") == 0:
        print("===== python stop =====")
    else:
        if os.system("py stop.py") == 0:
            print("=====py stop =====")
        else:
            if os.system("python3 stop.py") == 0:
                print("=====python3 stop =====")
            else:
                print("===== stop 失败 =====")
else:
    os.system('./stop.sh')

# 区分classpath分隔符
delimiter = ";" if isWindows else ":"

#


classpath = "-classpath "
classpath += "\""

for i in os.listdir("./target/classes/lib"):
    classpath += "./lib/"
    classpath += i
    classpath += delimiter
classpath += "\""

cmd = "cd target/classes && java -Dconfig=classpath:application-prod.yml -DdevMode=true "

cmd += classpath
cmd += " "
cmd += mainclass

# print(cmd)

read(os.popen(cmd))
os.popen(cmd)
